<?php 

namespace app\models;
use yii\db\ActiveRecord;
use yii;

 class Product extends ActiveRecord
 {
	 const AK='pS2iZhsvOrIsXhbKI4ec-hPvcmK6BhqQHcVvTRbU';
	 const SK='UbVlr7lgW0WViumImUPy8_qJIyNDWg5WDYnjblyZ';
	 const DOMAIN='opw1mtkjv.bkt.clouddn.com';
	 const BUKET='test-zifeng';
	 
	public $cate;
    public static function tableName(){
    return "{{%product}}";
    }
    public function attributeLabels(){
    	return [
    	'cateid'=>'分类名称',
    	'title'=>'商品名称',
    	'descr'=>'商品描述',
    	'price'=>'商品价格',
    	'ishot'=>'是否热卖',
    	'issale'=>'是否促销',
    	'saleprice'=>'促销价格',
    	'num'=>'库存',
    	'cover'=>'图片封面',
    	'image_list'=>'商品图片',
    	'ison'=>'是否上架',
    	'istui'=>'是否推荐',
    	];

    }
    public function rules()
    {
    	return [
 
    	['title','required','message'=>'标题不能为空'],
    	['descr','required','message'=>'描述不能为空'],
    	['cateid','required','message'=>'分类不能为空'],
    	[['price','saleprice'],'number','min'=>0.01,'message'=>'单价必须为必填'],
    	['num','integer','min'=>0,'message'=>'库存必须为数字'],
    	[['issale','ishot','istui'],'safe'],
    	[['cover'],'required'],
    	];
    }
    public function add($data){
    	$data['createtime']=time();
    	if($this->load($data) && $this->save()){
    		return true;
    	}
    	return false;
    }

  
 
 }